Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: App crashes when tapping more and share button in the Reader Details screen #20490

Merged

Conversation

salimbraksa
Copy link
Contributor

@salimbraksa salimbraksa commented Apr 6, 2023

Fixes #20487

Description

This PR fixed a bug that crashed the app when the user taps the more or share button in the Reader Details screen. This bug is only affecting iPad users.

Root Cause

This is the exact change in #20363 that caused the crash.

    func barButtonItem(with image: UIImage, action: Selector) -> UIBarButtonItem {
        let image = image.withRenderingMode(.alwaysTemplate)
-      let button = UIButton(frame: CGRect(x: 0, y: 0, width: 44.0, height: image.size.height))
-      button.setImage(image, for: UIControl.State())
-      button.addTarget(self, action: action, for: .touchUpInside)
- 
-       return UIBarButtonItem(customView: button)
+      return UIBarButtonItem(image: image, style: .plain, target: self, action: action)
    }

The code above removes usage of UIButton when creating a UIBarButtonItem, so the action param is now passed to a UIBarButtonItem instead of a UIButton. But the sender param of the action handlers was not updated accordingly.

// This method can be found in "ReaderDetailViewController.swift".
@objc private func didTapMenuButton(_ sender: UIButton) {
   // ...
}

The type of sender param type should be UIBarButtonItem instead of UIButton. The compiler didn't catch this, and I didn't either.

At runtime, however, the sender param type was UIBarButtonItem, which passed through several methods until it reached the following code.

// Can be found in `ReaderShowMenuAction.swift` and `PostSharingController.swift`.
if let presentationController = alertController.popoverPresentationController {
    presentationController.permittedArrowDirections = .any
    presentationController.sourceView = anchor
    presentationController.sourceRect = anchor.bounds
}

The presentationController.sourceView's type is UIView and anchor's type at runtime is UIBarButtonItem, thus the crash.

Screenshots

More Button Share Button

Test Instructions

Please perform the following tests on iPhone and iPad.

  1. Install the Jetpack app and log in.
  2. Head to Reader > Following or Reader > Discover
  3. Tap the More Button on any post.
  4. Expect a sheet to show up on iPhone and a popover to show up on iPad.
  5. Tap the post itself to reach the Reader Detail screen.
  6. Tap the More button.
  7. Expect a sheet/popover to appear.
  8. Tap the Share button.
  9. Expect a sheet/popover to appear.

Regression Notes

  1. Potential unintended areas of impact
    Double check the More and Share buttons work as expected in Reader Details and Reader Following / Discover screens.
Reader Details Reader Following & Discover Feeds
iPad
iPhone
  1. What I did to test those areas of impact (or what existing automated tests I relied on)
    Manual testing.

  2. What automated tests I added (or what prevented me from doing so)
    None.

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 7, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr20490-b99189a
Version22.1
Bundle IDorg.wordpress.alpha
Commitb99189a
App Center BuildWPiOS - One-Offs #5452
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Apr 7, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr20490-b99189a
Version22.1
Bundle IDcom.jetpack.alpha
Commitb99189a
App Center Buildjetpack-installable-builds #4481
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@salimbraksa salimbraksa requested a review from staskus April 7, 2023 00:36
@salimbraksa salimbraksa marked this pull request as ready for review April 7, 2023 00:36
@salimbraksa salimbraksa force-pushed the fix/20487-reader-crash-when-wtapping-more-share-button branch from 015a81e to 5571dc9 Compare April 7, 2023 00:54
@salimbraksa salimbraksa changed the base branch from trunk to release/22.1 April 7, 2023 00:54
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Apr 7, 2023

Warnings
⚠️

This PR contains changes to RELEASE_NOTES.txt.
Note that these changes won't affect the final version of the release notes as this version is in code freeze.
Please, get in touch with a release manager if you want to update the final release notes.

Generated by 🚫 dangerJS

Copy link
Contributor

@guarani guarani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works well! Thanks for the fix, @salimbraksa!

@salimbraksa salimbraksa added this to the 22.1 ❄️ milestone Apr 11, 2023
…iOS into fix/20487-reader-crash-when-wtapping-more-share-button
@salimbraksa salimbraksa requested a review from mokagio April 11, 2023 15:04
@mokagio
Copy link
Contributor

mokagio commented Apr 12, 2023

I find it spooky that this PR keeps failing in AccoutSettingsServiceTests however I don't see how the changes here could have affected those tests.

Moreover, there might be something dodgy down in the reporting layer, because looking at the logs we can see that the test eventually succeeds after retrying automatically

image

I see no reason to hold merging this PR because of that.

@mokagio mokagio merged commit 35ac8a9 into release/22.1 Apr 12, 2023
@mokagio mokagio deleted the fix/20487-reader-crash-when-wtapping-more-share-button branch April 12, 2023 05:08
@tiagomar
Copy link
Contributor

Hey @mokagio @salimbraksa , testUpdateFailure() is the least reliable unit test we have but in this case we have a 100% reliable test failing which is testShowShareSheet() and, for some unknown reason, it doesn't appear in the console logs with the red cross. However, we can see it listed among the Failing tests. So we'll need to either fix something in the code or fix the test.

Failing tests:
  AccountSettingsServiceTests.testUpdateFailure()
  AccountSettingsServiceTests.testUpdateFailure()
  ReaderDetailCoordinatorTests.testShowShareSheet()

image

image

@mokagio mokagio mentioned this pull request Apr 13, 2023
3 tasks
mokagio added a commit that referenced this pull request Apr 13, 2023
There were conflicts on `Podfile` and `Podfile.lock` because
`release/22.1` and `trunk` both changed the Gutenberg version.

As usual, I resolved them with `git checkout --theirs`, keeping the
value from `trunk` under the assumption that the latest version of
Gutenberg, 1.93.0-alpha2, is what `trunk` needs to work and that if the
1.92.1 hotfix hasn't already been integrated in the latest release, it
will be soon and the Gutenberg team will followup with a new version
update on `trunk`.

There was also a conflict on the `RELEASE-NOTES.txt` that GitHub picked
up with its more refined conflicts engine and that auto-merge didn't
address properly but that I manually fixed.

That was due to `release/22.1` adding new release note entries – which
will not make it into the App Store release notes – in the 22.1 section
and `trunk` having #20128 editing that section, too. #20128 was meant to
land on `release/22.1` but I forgot to update the base branch after
starting the code freeze 🤦‍♂️😭

```
<<<<<<< release/22.1 -- Incoming Change
* [**] Add a "Personalize Home Tab" button to the bottom of the Home tab that allows changing cards visibility. [#20369]
* [*] [Reader] Fix an issue that was causing the app to crash when tapping the More or Share buttons in Reader Detail screen. [#20490]
* [*] Block editor: Avoid empty Gallery block error [WordPress/gutenberg#49557]
=======
* [**] [internal] Refactored Google SignIn implementation to not use the Google SDK [#20128]
>>>>>>> trunk -- Current Change
```
@mokagio mokagio mentioned this pull request Apr 13, 2023
3 tasks
@@ -8,6 +8,7 @@
* [***] [internal] Refactor uploading photos (from the device photo, the Free Photo library, and other sources) to the WordPress Media Library. Affected areas are where you can choose a photo and upload, including the "Media" screen, adding images to a post, updating site icon, etc. [#20322]
* [**] [WordPress-only] Warns user about sites with only individual plugins not supporting core app features and offers the option to switch to the Jetpack app. [#20408]
* [**] Add a "Personalize Home Tab" button to the bottom of the Home tab that allows changing cards visibility. [#20369]
* [*] [Reader] Fix an issue that was causing the app to crash when tapping the More or Share buttons in Reader Detail screen. [#20490]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice that since this landed in the release branch after code freeze, the App Store release notes won't include it.

mokagio added a commit that referenced this pull request Apr 13, 2023
There were conflicts on `Podfile` and `Podfile.lock` because
`release/22.1` and `trunk` both changed the Gutenberg version.

As usual, I resolved them with `git checkout --theirs`, keeping the
value from `trunk` under the assumption that the latest version of
Gutenberg, 1.93.0-alpha2, is what `trunk` needs to work and that if the
1.92.1 hotfix hasn't already been integrated in the latest release, it
will be soon and the Gutenberg team will followup with a new version
update on `trunk`.

There was also a conflict on the `RELEASE-NOTES.txt` that GitHub picked
up with its more refined conflicts engine and that auto-merge didn't
address properly but that I manually fixed.

That was due to `release/22.1` adding new release note entries – which
will not make it into the App Store release notes – in the 22.1 section
and `trunk` having #20128 editing that section, too. #20128 was meant to
land on `release/22.1` but I forgot to update the base branch after
starting the code freeze 🤦‍♂️😭

Also, the entry about the personalize home tab had been removed on
`trunk` via ec8a377. The release notes
editor was notified about it,
#20483 (review)

```
<<<<<<< release/22.1 -- Incoming Change
* [**] Add a "Personalize Home Tab" button to the bottom of the Home tab that allows changing cards visibility. [#20369]
* [*] [Reader] Fix an issue that was causing the app to crash when tapping the More or Share buttons in Reader Detail screen. [#20490]
* [*] Block editor: Avoid empty Gallery block error [WordPress/gutenberg#49557]
=======
* [**] [internal] Refactored Google SignIn implementation to not use the Google SDK [#20128]
>>>>>>> trunk -- Current Change
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reader: Crash on iPad after tapping more/share button in the details view
5 participants